package com.github.shiqiyue.learn.guava;

import com.google.common.util.concurrent.RateLimiter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/***
 * RateLimiter 测试
 * @author wenyao.wu
 * @date 2018/7/2
 */
public class RateLimitTest {

    private static final Logger logger = LoggerFactory.getLogger(RateLimitTest.class);

    public static void main(String[] args) {
        /***
         * 每秒生成两个资源
         */
        RateLimiter limiter = RateLimiter.create(2.0);
        Integer num = 1000;
        for (int i = 0; i < num; i++) {
            double time = limiter.acquire();
            logger.info("get limter, use time : {}", time);
        }

    }


}
